package com.gxa.controller;

import com.gxa.pojo.Coupon;
import com.gxa.service.CouponService;
import com.gxa.utils.ResponseData;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;

/**
 * Created with IntelliJ IDEA.
 * User: hw
 * Date: 2020/11/26 11:14
 * Description:
 * Version: V1.0
 */
@RestController
@RequestMapping("/coupon")
@Api(value = "优惠券管理",tags = "优惠券管理API")
public class CouponController {

    @Autowired(required = false)
    private ResponseData responseData;
    @Autowired(required = false)
    private CouponService couponService;

    @RequestMapping(value = "/queryCoupon",produces = "application/json;charset=utf-8")
    @ApiOperation(value = "查询优惠券管理信息",notes = "查询优惠券管理信息",httpMethod = "GET")
    public ResponseData queryCoupon()   {
        List<Coupon> list = new ArrayList();
        Coupon coupon = new Coupon();
        Coupon coupon1 = new Coupon();

        coupon.setCouponId(1);
        coupon.setCouponName("用户发放优惠券");
        coupon.setCouponType(1);
        coupon.setCouponAmount(2.00);
        coupon.setCouponLol(1.00);
        coupon.setCouponQi(500);
        coupon.setCouponUa(338);
         String date = "2020-11-01 15:20:12";
        Date parse = null;
        try {
            parse = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(date);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        coupon.setCouponEd(parse);
        String date1 =("2020-12-01 08:30:00");
        Date parse1 = null;
        try {
            parse1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(date1);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        coupon.setCouponEdf(parse1);

        coupon1.setCouponId(2);
        coupon1.setCouponName("订单发放优惠券");
        coupon1.setCouponType(2);
        coupon1.setCouponAmount(1.00);
        coupon1.setCouponLol(0.50);
        coupon1.setCouponQi(200);
        coupon1.setCouponUa(80);
        String date2 = "2020-11-01 15:20:12";
        Date parse2 = null;
        try {
            parse2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(date2);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        coupon1.setCouponEd(parse2);
        String date3 =("2020-12-01 08:30:00");
        Date parse3 = null;
        try {
            parse3 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(date3);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        coupon1.setCouponEdf(parse3);

        list.add(coupon);
        list.add(coupon1);

        if (list != null){
            responseData.setCode(200);
            responseData.setMsg("查询成功");
            responseData.setData(list);
        }else {
            responseData.setCode(500);
            responseData.setMsg("查询失败");
        }
        return responseData;
    }

    @RequestMapping(value = "/updateCouponById",produces = "application/json;charset=utf-8")
    @ApiOperation(value = "根据ID修改优惠券",notes = "根据ID修改优惠券",httpMethod = "POST")
    public ResponseData updateCouponById(Integer couponId){

        if(couponId > 0){
            responseData.setCode(200);
            responseData.setMsg("修改成功");
//            responseData.setData(coupon);
        }else {
            responseData.setCode(500);
            responseData.setMsg("修改失败");
        }
        return responseData;
    }

    @RequestMapping(value = "/delCouponById",produces = "application/json;charset=utf-8")
    @ApiOperation(value = "根据ID删除优惠券",notes = "根据ID删除优惠券",httpMethod = "POST")
    public ResponseData delCouponById(Integer couponId){

        if(couponId > 0){
            responseData.setCode(200);
            responseData.setMsg("删除成功");
//            responseData.setData(coupon);
        }else {
            responseData.setCode(500);
            responseData.setMsg("删除失败");
        }
        return responseData;
    }

    @RequestMapping(value = "/queryCouponById",produces = "application/json;charset=utf-8")
    @ApiOperation(value = "根据ID查询优惠券",notes = "根据ID查询优惠券",httpMethod = "GET")
    public ResponseData queryCouponById(Integer couponId){

        if(couponId > 0){
            responseData.setCode(200);
            responseData.setMsg("查询成功");
//            responseData.setData(coupon);
        }else {
            responseData.setCode(500);
            responseData.setMsg("查询失败");
        }
        return responseData;
    }


    @RequestMapping(value = "/addCouponByCouponType",produces = "application/json;charset=utf-8")
    @ApiOperation(value = "添加优惠券",notes = "添加优惠券",httpMethod = "POST")
    public ResponseData addCouponByCouponType(Coupon coupon) {

        if (coupon != null) {
            responseData.setCode(200);
            responseData.setMsg("添加成功");
            responseData.setData(coupon);
        } else {
            responseData.setCode(500);
            responseData.setMsg("添加失败");
        }
        return responseData;
    }


    @RequestMapping(value = "/queryCouponBycouponType",produces = "application/json;charset=utf-8")
    @ApiOperation(value = "根据类型查询优惠券",notes = "根据类型查询优惠券",httpMethod = "GET")
    public ResponseData queryCouponBycouponType(String couponType){

        Map map = new HashMap();
        map.put("couponNum",2017061515);
        map.put("couponType","关注发放");
        map.put("orderCode","2017090654555351");
        map.put("memberNn","不知道先森");
        map.put("couponUt","未使用");
        if (couponType != null) {
            responseData.setCode(200);
            responseData.setMsg("添加成功");
            responseData.setData(map);
        } else {
            responseData.setCode(500);
            responseData.setMsg("添加失败");
        }
        return responseData;
    }

    @RequestMapping(value = "/delCouponBycouponId",produces = "application/json;charset=utf-8")
    @ApiOperation(value = "根据ID删除优惠券",notes = "根据ID删除优惠券",httpMethod = "POST")
    public ResponseData delCouponBycouponId(Integer couponId){

        if (couponId > 0) {
            responseData.setCode(200);
            responseData.setMsg("删除成功");
//            responseData.setData(map);
        } else {
            responseData.setCode(500);
            responseData.setMsg("删除失败");
        }
        return responseData;
    }

    @RequestMapping(value = "/updateCouponByType",produces = "application/json;charset=utf-8")
    @ApiOperation(value = "根据类型修改优惠券",notes = "根据类型修改优惠券",httpMethod = "POST")
    public ResponseData updateCouponByType(Integer couponType){

        if (couponType > 0) {
            responseData.setCode(200);
            responseData.setMsg("修改成功");
//            responseData.setData(map);
        } else {
            responseData.setCode(500);
            responseData.setMsg("修改失败");
        }
        return responseData;
    }

}
